import * as echarts from 'echarts';

export default {
    setOption: (xData, yData, xName = '', yName = '', title, yMin, yMax) => {
        return {
            //提示框组件
            tooltip: {
                trigger: 'axis',
                position: function (pt) {
                    return [pt[0], '10%'];
                }
            },
            title: {
                left: 'center',
                text: title
            },
            toolbox: {
                orient: 'vertical',
                feature: {
                    dataZoom: {
                        yAxisIndex: 'none'
                    },
                    magicType: { type: ['line', 'bar'] }
                }
            },
            xAxis: {
                type: 'category',
                name: xName,
                axisLabel: {
                    interval: 0
                },
                boundaryGap: false,
                data: xData.map(item => echarts.format.formatTime('yyyy-MM-dd\nhh:mm:ss', item))
            },
            yAxis: {
                type: 'value',
                name: yName,
                boundaryGap: [0, '100%'],
                min: yMin,
                max: yMax
            },
            grid: {
                bottom: 80
            },
            series: [{
                data: yData,
                type: 'line',
                smooth: true,
                symbol: 'none',
                sampling: 'average'
            }],
            textStyle: {
                fontSize: 12
            },
            animation: false
        };
    }
};
